home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / maxjm110.zip / MAXJM.C < prev    next >
C/C++ Source or Header  |  1991-05-20  |  7KB  |  164 lines

  1.  
  2.  
  3.  /*[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]
  4.  [*]                                                                       [*]
  5.  [*]                                                                       [*]
  6.  [*]  MaxJM -- a program to run the JModem protocol for the Maximus BBS.   [*]
  7.  [*]  Version -- 1.10                                                      [*]
  8.  [*]                                                                       [*]
  9.  [*]                                                                       [*]
  10.  [*]  Written by Ray Kaliss of FidoNet 1:141/840.                          [*]
  11.  [*]  Later hacked on and modified by Randy Edwards.                       [*]
  12.  [*]                                                                       [*]
  13.  [*]                                                                       [*]
  14.  [*]  Command line parameters: none                                        [*]
  15.  [*]                                                                       [*]
  16.  [*]                                                                       [*]
  17.  [*]  Errorlevels returned:                                                [*]
  18.  [*]                                                                       [*]
  19.  [*]      255 = Bad parameter passed in a case statement. Programmer's     [*]
  20.  [*]            error that should never happen.                            [*]
  21.  [*]                                                                       [*]
  22.  [*]      254 = Error reading MaxJM.CTL file created by Maximus/Opus.      [*]
  23.  [*]            Unlikely to happen.                                        [*]
  24.  [*]                                                                       [*]
  25.  [*]      253 = Unspecified error while doing the DOS shell. Out of        [*]
  26.  [*]            memory probably, couldn't find COMSPEC variable, etc.      [*]
  27.  [*]                                                                       [*]
  28.  [*]      252 = Error opening MaxJM.CTL file -- i.e. file not found.       [*]
  29.  [*]                                                                       [*]
  30.  [*]        1 = Everything went okay except the file transfer aborted.     [*]
  31.  [*]                                                                       [*]
  32.  [*]        0 = All successful.  Successful shell to JMBatch.* done.       [*]
  33.  [*]                                                                       [*]
  34.  [*]                                                                       [*]
  35.  [*]  Compiler: Turbo C 2.01      Compiler switches: nothing special       [*]
  36.  [*]                                                                       [*]
  37.  [*]                                                                       [*]
  38.  [*]  Program/compiling/library notes: none                                [*]
  39.  [*]                                                                       [*]
  40.  [*]                                                                       [*]
  41.  [*]  Bugs/known problems/deficiencies: Could use comprehensive error      [*]
  42.  [*]      checking on all file operations.                                 [*]
  43.  [*]                                                                       [*]
  44.  [*]                                                                       [*]
  45.  [*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]*/
  46.  
  47.  
  48. #include <dir.h>
  49. #include <process.h>
  50. #include <sys/stat.h>
  51. #include <stdio.h>
  52. #include <string.h>
  53.  
  54.  
  55. main()
  56. {
  57.     FILE *InputFileStream;
  58.     char xload[80], xfer[10];
  59.     char tsend[10] = "Send", tget[10] = "Get ";
  60.  
  61.     puts("\r\nMax-JModem: an external JMODEM file transfer interface program for Max/Opus.");
  62.     puts("Written by Ray Kaliss of 1:141/840, hacked on by Randy Edwards.\r\n");
  63.  
  64.     if ((InputFileStream = fopen("maxjm.ctl", "r")) == NULL) {
  65.         puts("Error: Control file MAXJM.CTL not found.");
  66.         getout(252);
  67.     }
  68.     fgets(xload, 80, InputFileStream);
  69.     fgets(xload, 80, InputFileStream);
  70.     fgets(xload, 80, InputFileStream);
  71.     fgets(xload, 80, InputFileStream);
  72.     fgets(xload, 80, InputFileStream);
  73.     fgets(xload, 80, InputFileStream);
  74.     fgets(xload, 9, InputFileStream);
  75.     fgets(xload, 80, InputFileStream);
  76.     fgets(xload, 80, InputFileStream);
  77.     fgets(xload, 80, InputFileStream);
  78.  
  79.     fgets(xfer, 5, InputFileStream);          /* fgets the 'Send' or 'Get' */
  80.     fgets(xload, 80, InputFileStream);    /* Advance down to the next line */
  81.     fgets(xload, 4, InputFileStream);
  82.     fgets(xload, 30, InputFileStream);
  83.     fclose(InputFileStream);
  84.  
  85.     if (strncmpi(tsend, xfer, 3) == 0) {           /* If it's a "Send" ... */
  86.         getout(do_it(xload, 'S'));
  87.     }
  88.     else if (strncmpi(tget, xfer, 3) == 0) {          /* If it's a 'Get' ... */
  89.         getout(do_it(xload, 'G'));
  90.     }
  91.     else { puts("Error: Unable to properly read MAXJM.CTL file.");
  92.         getout(254);
  93.     }
  94.     /* We should never hit the below line. */
  95.     return(0);
  96. }  /* End of function main() */
  97.  
  98. /*------------------------------ Functions -------------------------------*/
  99.  
  100. /*  do_it -- a function to do the actual shell, check for an aborted transfer
  101.              and to write out the MAXJM.LOG log file.  */
  102. int do_it(filename, get_send)
  103. char get_send;
  104. char filename[80];
  105. {
  106.     FILE *OutputFileStream;
  107.     struct ffblk ffblock;
  108.     struct stat filestats;
  109.     char fdrive[MAXDRIVE], fdir[MAXDIR], fname[MAXFILE], fext[MAXEXT];
  110.     char command[80], log_line[10];
  111.     char flagfile[] = "MAXJM.FLG";
  112.     int found, errflag;
  113.  
  114.     errflag = 0;
  115.     switch (toupper(get_send)) {
  116.         case 'G':   strcpy(command, "JMBatch R ");
  117.             strcat(command, filename);
  118.             strcpy(log_line, "Got ");
  119.             break;
  120.         case 'S':   strcpy(command, "JMBatch S ");
  121.             strcat(command, filename);
  122.             strcpy(log_line, "Sent ");
  123.             break;
  124.         default:
  125.             puts("Bad parameter passed as get_send.");
  126.             getout(255);
  127.             break;
  128.     }
  129.     printf("Shelling out to JMBATCH: %s ", command);
  130.     if (system(command) != 0)         /* If the shell was bad set errflag. */
  131.         errflag = 253;
  132.  
  133.     found = findfirst(flagfile, &ffblock, 0);        /* Check for flag-file. */
  134.     if (found == 0) {                /* If we find the flag file, erase it */
  135.         unlink(flagfile);               /* because it was a bad file xfer. */
  136.         errflag = 1;             /* Set errorflag for an aborted transfer. */
  137.     }
  138.     else if (errflag == 0) {   /* The shell was successful + no flag-file. */
  139.         filename[strlen(filename)-1] = '\0'; /* Zap the \n on string filename. */
  140.         if (stat(filename, &filestats) != 0)
  141.             filestats.st_size = 100000; /* If we don't know the size, use 100k. */
  142.         fnsplit(filename, fdrive, fdir, fname, fext);
  143.         strcpy(filename, fname);  /* Break filename down into only NAME.EXT. */
  144.         strcat(filename, fext);
  145.         OutputFileStream = fopen("maxjm.log", "w");    /* Write it out ... */
  146.         fprintf(OutputFileStream, "%s%s %i\r\n", log_line, filename, filestats.st_size);
  147.         fprintf(OutputFileStream, " file\r\n");    /* Is this line needed?! */
  148.         fclose(OutputFileStream);
  149.     }
  150.     return(errflag);
  151. }
  152.  
  153.  
  154. /*  getout -- a general exit-with-errorlevel function.  */
  155. int getout(int errorlevel)
  156. {
  157.     fcloseall();
  158.     printf("\n\rMax-JModem ending with errorlevel %i.\n\r", errorlevel);
  159.     exit(errorlevel);
  160.     return(0);
  161. }
  162.  
  163.  
  164.